﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class DispinterfacePropertyElement : IdElement, ISectionElementElement
    {
        private IndexIntervalElement indexinterval;
        private ITypeElement type;
        private bool isreadonly;
        private PropertyOptionElement dispid;
        private bool _default;

        public IndexIntervalElement IndexInterval { get { return indexinterval; } set { indexinterval = value; } }
        public ITypeElement Type { get { return type; } set { type = value; } }
        public bool IsReadOnly { get { return isreadonly; } set { isreadonly = value; } }
        public PropertyOptionElement Dispid { get { return dispid; } set { dispid = value; } }
        public bool Default { get { return _default; } set { _default = value; } }

        public DispinterfacePropertyElement(TokenInfo Id, IndexIntervalElement IndexInterval, bool IsReadOnly, PropertyOptionElement Dispid, bool Default, List<TokenInfo> Comments)
            : base(Id, Comments)
        {
            indexinterval = IndexInterval;
            type = Type;
            isreadonly = IsReadOnly;
            dispid = Dispid;
            _default = Default;
        }

        public override string ToString()
        {
            string result = string.Format("property {0}", id);
            if (indexinterval != null) result += string.Format(" {0}", indexinterval);
            if (type != null) result += string.Format(" : {0}", type);
            if (isreadonly) result += " readonly";
            if (dispid != null) result += string.Format(" {0}", dispid);
            if (_default) result += "; default";
            return result;
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (indexinterval != null)
                yield return indexinterval;
            if (type != null)
                yield return type;
            if (dispid != null)
                yield return dispid;
        }
    }
}
